package com.may.wind.controller;

import com.may.wind.entity.User;
import com.may.wind.pojo.Result;
import com.may.wind.service.UserRoleService;
import com.may.wind.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 风
 */
@RestController
@Api(tags = "用户相关API")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    UserRoleService adminUserRoleService;

    /**
     * 获取用户列表
     *
     * @return 用户列表
     */
    @ApiOperation(value = "获取用户列表", httpMethod = "GET")
    @GetMapping("/api/user/getUsers")
    public Result getUsers() {
        List<User> users = userService.finaAll();
        return Result.ok().data("users", users);
    }

    /**
     * 更新用户状态
     *
     * @param user 用户
     * @return 操作结果
     */
    @ApiOperation(value = "更新用户状态", httpMethod = "PUT")
    @ApiImplicitParam(name = "user", value = "用户", required = true)
    @PutMapping("/api/user/updateUserStatus")
    public Result updateUserStatus(@RequestBody @Valid User user) {
        userService.updateUserStatus(user);
        return Result.ok().data("message", "用户状态更新成功");
    }

    /**
     * 重置用户密码
     *
     * @param user 用户
     * @return 操作结果
     */
    @ApiOperation(value = "重置用户密码", httpMethod = "PUT")
    @ApiImplicitParam(name = "user", value = "用户", required = true)
    @PutMapping("/api/user/resetPassword")
    public Result resetPassword(@RequestBody @Valid User user) {
        userService.resetPassword(user);
        return Result.ok().data("message", "重置密码成功");
    }

    /**
     * 修改用户信息
     *
     * @param user 用户
     * @return 操作结果
     */
    @ApiOperation(value = "修改用户信息", httpMethod = "PUT")
    @ApiImplicitParam(name = "user", value = "用户", required = true)
    @PutMapping("/api/user/editUser")
    public Result editUser(@RequestBody @Valid User user) {
        userService.editUser(user);
        return Result.ok().data("message", "修改用户信息成功");
    }
}
